using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    class MRPUsersService 
    {
        ISession session;

        public MRPUsersService(ISession session)
        {
            this.session = session;
        }
        public MRPUsersService( )
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpusers(MRPUsers mrpusersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpusersX);
            tx.Commit();
        }

        public void UpdateMrpusers(MRPUsers mrpusersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpusersX);
            tx.Commit();
        }

        public void DeleteMrpusers(MRPUsers mrpusersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpusersX);
            tx.Commit();
        }

        public IList<MRPUsers> GetAllMrpusers(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPUsers");
            IList<MRPUsers> list = query.List<MRPUsers>();
            if (evict)
            {
                foreach (MRPUsers s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPUsers GetAllMrpusersByID(String id,Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPUsers as c where c.Usercode= :x");
            query.SetString("x", id);
            MRPUsers s = (MRPUsers)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPUsers> GetMrpusersByQuery(IQuery query,Boolean evict)
        {
            IList<MRPUsers> list = query.List<MRPUsers>();
            if (evict)
            {
                foreach (MRPUsers s in list)
                {
                session.Evict(s);
                }
            }
            return list;
        }
    }
}
